package net.optix.ip.business
{
	import com.adobe.cairngorm.business.Responder;
	
	import mx.rpc.http.HTTPService;
	
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.ActionVO;
	import net.optix.ip.vo.FirmVO;
	import net.optix.ip.vo.InventionVO;
	import net.optix.ip.vo.RenewalFeeVO;
	import net.optix.ip.vo.TradeSecretVO;
	import net.optix.ip.vo.ValueVO;
	
	public class InventionDelegate
	{
		private var responder:Responder;
		private var service:HTTPService;
		
		public function	listener():void
		{
			service.method = "POST";
            service.resultFormat	=	HTTPService.RESULT_FORMAT_E4X;
            service.addEventListener("result", responder.onResult);
            service.addEventListener("fault", responder.onFault);
		}

		public function getInventions(responder:Responder,role:int,userID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetInventions";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	Role:role,
            	UserID:userID
            });
		}
		
		public function getInvention(responder:Responder,inventionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetInvention";
            this.listener();
            service.send({
            	InventionID:inventionID
            });
		}
		
		public function inviteeFirm(responder:Responder,email:String,message:String):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/InviteeFirm";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	Email:email,Message:message
            });
		}
		
		public function renewalFee(responder:Responder,vo:RenewalFeeVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/RenewalFee";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	FirmID:vo.firmID,
            	RenewalDate:vo.renewalDate,
            	ReferenceNumber:vo.referenceNumber
            });
		}
		
		public function getActions(responder:Responder,inventionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetActions";
            
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:inventionID
            });
		}
		
		public function getResponseActions(responder:Responder,actionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetResponseActions";
            
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	ActionID:actionID
            });
		}
		
		public function getOfficeActions(responder:Responder,inventionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetOfficeActions";
            this.listener();
            service.send({
            	InventionID:inventionID
            });
		}
		
		public function addInvention(responder:Responder,vo:InventionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AddInvention";
            this.listener();
            
            service.send({Title:vo.title,
				KeyWords:vo.keyWords,
				Docket:vo.docket,
				Invented:vo.invented,
				Type:vo.type,
				Status:vo.status,
				FileNames:vo.fileNames,
				Description:vo.description,
				ClientID:vo.clientID,
				InventorID:vo.inventorID});
		}
		
		public function addAction(responder:Responder,vo:ActionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AddAction";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
				InventionID:vo.inventionID,
				Title:vo.title,
				Type:vo.type,
				Description:vo.description,
				FileNames:vo.fileNames,
				Cost:vo.cost
			});
		}
		
		public function responseToOffice(responder:Responder,vo:ActionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/ResponseToOffice";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
				ResponseActionID:vo.responseActionID,
				Type:vo.type,
				Description:vo.description,
				FileNames:vo.fileNames,
				Cost:vo.cost,
				ResponseDate:vo.responseDate
			});
		}
		
		public function addFieldAction(responder:Responder,vo:ActionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AddFieldAction";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            
			service.send({InventionID:vo.inventionID,
				Title:vo.title,
				Type:vo.type,
				Description:vo.description,
				FillingDate:vo.fillingDate,
				SerialNumber:vo.serialNumber,
				FileNames:vo.fileNames,
				Cost:vo.cost,
				Status:vo.inventionType
			});
		}
		
		public function addOfficeAction(responder:Responder,vo:ActionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AddOfficeAction";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	OfficeActionMailed:vo.actionMailed,
            	OfficeActionType:vo.type,
            	OfficeActionResponse:vo.responseDate,
            	Comments:vo.comments,
            	ResponseField:vo.responseField,
            	ResponseType:vo.responseType,
				Cost:vo.cost,
				ResponseDueDate:vo.responseDueDate
            });
		}
		
		public function updateInvention(responder:Responder,vo:InventionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/UpdateInvention";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({InventionID:vo.inventionID,
				Type:vo.type,
				Status:vo.status,
				BBid:vo.bBid,
				MaxBudget:vo.maxBudget,
				IssueDate:vo.issueDate,
				Title:vo.title,
				Docket:vo.docket,
				KeyWords:vo.keyWords,
				Description:vo.description});
		}
		
		public function publishInvention(responder:Responder,inventionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/PublishInvention";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:inventionID
				});
		}
		
		public function getBidInventions(responder:Responder,firmID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetBidInventions";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({FirmID:firmID});
		}
		
		public function editFirm(responder:Responder,vo:FirmVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/EditFirm";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	FirmID:vo.firmID,
            	Name:vo.name,
				Address:vo.address,
				City:vo.city,
				State:vo.state,
				PostalCode:vo.postalCode,
				Country:vo.country});
		}
		
		public function getValue(responder:Responder,inventionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetValue";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:inventionID});
		}
		
		public function setValue(responder:Responder,value:ValueVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/SetValue";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
				InventionID:value.inventionID,
				Valuation:value.auction,
				
				Area:value.area,
				Definition:value.definition,
				Rev:value.rev,
				Tam:value.tam,
				Sam:value.sam,
				Impact:value.impact,
				Grow:value.grow,
				
				Asp:value.asp,
				Ca:value.ca,
				Pa:value.pa,
				Devcost:value.devcost,
				Altad:value.altad,
				
				Funcad:value.funcad,
				Samepb:value.samepb,
				Pat1pb:value.pat1pb,
				Pat2pb:value.pat2pb,
				Blk1pb:value.blk1pb,
				Blk2pb:value.blk2pb
            });
		}
		
		public function getInventionBudgets(responder:Responder,inventionID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetInventionBudgets";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:inventionID});
		}
		
		public function assignToFirmOther(responder:Responder,vo:InventionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AssignToFirmOther";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	FirmID:vo.firmID,
            	DeadlineDate:vo.deadlineDate,
            	MaxBudget:vo.maxBudget});
		}
		
		public function acceptAssignInvention(responder:Responder,vo:InventionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AcceptAssignInvention";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	FirmID:vo.firmID,
            	BConfirm:vo.bConfirm});
		}
		
		public function setMaxBudget(responder:Responder,vo:InventionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/SetMaxBudget";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	MaxBudget:vo.maxBudget});
		}
		
		public function saveFirmDocket(responder:Responder,vo:InventionVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/SaveFirmDocket";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	FirmDocket:vo.firmDocket});
		}
		
		public function assignToPractitioner(responder:Responder,inventionID:int,practitionerID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/AssignToPractitioner";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:inventionID,
            	PractitionerID:practitionerID});
		}
		
		public function getTrackInventions(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetTrackInventions";
            this.listener();
           	//service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	ClientID:clientID
            });
		}
		
		public function getTrackInventionsByFirm(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/GetTrackInventionsByFirm";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	ClientID:clientID
            });
		}
		
		public function recordTradeSecret(responder:Responder,vo:TradeSecretVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/RecordTradeSecret";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:vo.inventionID,
            	ClientID:vo.clientID,
				TradeSecret:vo.tradeSecret,
				InfExtentOut:vo.infExtentOut,
				InfExtentIn:vo.infExtentIn,
				InfValue:vo.infValue,
				InfTime:vo.infTime,
				InfDiff:vo.infDiff,
				InfMeasures:vo.infMeasures,
				InfSum:vo.infSum,
				StrExtentOut:vo.strExtentOut,
				StrExtentIn:vo.strExtentIn,
				StrValue:vo.strValue,
				StrTime:vo.strTime,
				StrDiff:vo.strDiff,
				StrMeasures:vo.strMeasures
            	});
		}
		
		public function protectAsSecret(responder:Responder,inventionID:int,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Invention/ProtectAsSecret";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	InventionID:inventionID,
            	ClientID:clientID
            });
		}
	}
}